import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:taonile/utils/common_utils.dart';

import '../config/config.dart';
import '../entity/goods_area_category_entity.dart';
import '../entity/goods_source_list_entity.dart';
import '../routers/routers.dart';

Widget getMallHomeModule1(String imgUrl) {
  return Container(
    margin: EdgeInsets.only(top: 40.w, left: 25.w, right: 25.w),
    width: double.infinity,
    height: 300.w,
    child: ClipRRect(
      borderRadius: BorderRadius.circular(12.w),
      child: Image.network(
        imgUrl,
        fit: BoxFit.fill,
        width: double.infinity,
        height: double.infinity,
      ),
    ),
  );
}

Widget getMallHomeModule3(String imgUrl1, String imgUrl2, String imgUrl3) {
  return Container(
    margin: EdgeInsets.only(top: 40.w, left: 25.w, right: 25.w),
    decoration: const BoxDecoration(color: Colors.transparent),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          margin: const EdgeInsets.symmetric(vertical: 0, horizontal: 0),
          child: Row(
            children: [
              Text('活动专区', style: TextStyle(color: (Config.colorText1), fontSize: 30.sp)),
            ],
          ),
        ),
        Container(
          height: 320.w,
          margin: EdgeInsets.only(top: 20.w),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              SizedBox(
                width: 222.w,
                height: double.infinity,
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(12.w),
                  child: Image.network(
                    imgUrl1,
                    fit: BoxFit.fill,
                    width: double.infinity,
                    height: double.infinity,
                  ),
                ),
              ),
              SizedBox(
                width: 222.w,
                height: double.infinity,
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(12.w),
                  child: Image.network(
                    imgUrl2,
                    fit: BoxFit.fill,
                    width: double.infinity,
                    height: double.infinity,
                  ),
                ),
              ),
              SizedBox(
                width: 222.w,
                height: double.infinity,
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(12.w),
                  child: Image.network(
                    imgUrl3,
                    fit: BoxFit.fill,
                    width: double.infinity,
                    height: double.infinity,
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    ),
  );
}

Widget getMallHomeModule3Special(BuildContext context, List<GoodsAreaCategoryData> data) {
  return Container(
    margin: EdgeInsets.only(top: 35.w, left: 25.w, right: 25.w),
    decoration: const BoxDecoration(color: Colors.transparent),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          height: 400.w,
          margin: EdgeInsets.only(top: 20.w),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              InkWell(
                onTap: () {
                  if (data.isEmpty) {
                    return;
                  }
                  Routes.navigateTo(
                    context,
                    Routes.productSpecial,
                    params: {'pageTitle': data[0].name, 'areaId': data[0].id},
                  );
                },
                child: SizedBox(
                  width: 280.w,
                  height: double.infinity,
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(12.w),
                    child: CachedNetworkImage(
                      imageUrl: data.isNotEmpty
                          ? CommonUtils.compressImageUrl(data[0].imgPath, 280, 400)
                          : '',
                      fit: BoxFit.fill,
                      width: double.infinity,
                      height: double.infinity,
                      errorWidget: (context, url, error) {
                        return Image.asset(
                          'assets/images/bg_default_400.png',
                          width: double.infinity,
                          height: double.infinity,
                          fit: BoxFit.fill,
                        );
                      },
                    ),
                  ),
                ),
              ),
              SizedBox(
                width: 400.w,
                height: double.infinity,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    InkWell(
                      onTap: () {
                        if (data.length < 2) {
                          return;
                        }
                        Routes.navigateTo(
                          context,
                          Routes.productSpecial,
                          params: {'pageTitle': data[1].name, 'areaId': data[1].id},
                        );
                      },
                      child: SizedBox(
                        height: 190.w,
                        width: double.infinity,
                        child: ClipRRect(
                          borderRadius: BorderRadius.circular(12.w),
                          child: CachedNetworkImage(
                            imageUrl: data.length > 1
                                ? CommonUtils.compressImageUrl(data[1].imgPath, 400, 190)
                                : '',
                            fit: BoxFit.fill,
                            width: double.infinity,
                            height: double.infinity,
                            errorWidget: (context, url, error) {
                              return Image.asset(
                                'assets/images/bg_default_400.png',
                                width: double.infinity,
                                height: double.infinity,
                                fit: BoxFit.fill,
                              );
                            },
                          ),
                        ),
                      ),
                    ),
                    InkWell(
                      onTap: () {
                        if (data.length < 3) {
                          return;
                        }
                        Routes.navigateTo(
                          context,
                          Routes.productSpecial,
                          params: {'pageTitle': data[2].name, 'areaId': data[2].id},
                        );
                      },
                      child: SizedBox(
                        height: 190.w,
                        width: double.infinity,
                        child: ClipRRect(
                          borderRadius: BorderRadius.circular(12.w),
                          child: CachedNetworkImage(
                            imageUrl: data.length > 2
                                ? CommonUtils.compressImageUrl(data[2].imgPath, 400, 190)
                                : '',
                            fit: BoxFit.fill,
                            width: double.infinity,
                            height: double.infinity,
                            errorWidget: (context, url, error) {
                              return Image.asset(
                                'assets/images/bg_default_400.png',
                                width: double.infinity,
                                height: double.infinity,
                                fit: BoxFit.fill,
                              );
                            },
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ],
    ),
  );
}

Widget getMallHomeModule4(BuildContext context, List<GoodsSourceListData> sourceList) {
  return Container(
    margin: EdgeInsets.only(top: 30.w, left: 25.w, right: 25.w),
    decoration: const BoxDecoration(color: Colors.transparent),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        // Container(
        //   margin: const EdgeInsets.symmetric(vertical: 0, horizontal: 0),
        //   child: Row(
        //     children: [
        //       Text('测试标题', style: TextStyle(color: (Config.colorText1), fontSize: 30.sp)),
        //     ],
        //   ),
        // ),
        Container(
          height: 170.w,
          margin: EdgeInsets.only(top: 20.w),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              SizedBox(
                width: 342.w,
                height: double.infinity,
                child: InkWell(
                  onTap: () {
                    if (sourceList.isEmpty) {
                      return;
                    }
                    Routes.navigateTo(context, Routes.productList,
                        params: {'sourceId': sourceList[0].id});
                  },
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(12.w),
                    child: CachedNetworkImage(
                      imageUrl: sourceList.isNotEmpty
                          ? CommonUtils.compressImageUrl(sourceList[0].imgPath, 342, 170)
                          : '',
                      fit: BoxFit.fill,
                      width: double.infinity,
                      height: double.infinity,
                      errorWidget: (context, url, error) {
                        return Image.asset(
                          'assets/images/bg_default_400.png',
                          width: double.infinity,
                          height: double.infinity,
                          fit: BoxFit.fill,
                        );
                      },
                    ),
                  ),
                ),
              ),
              SizedBox(
                width: 342.w,
                height: double.infinity,
                child: InkWell(
                  onTap: () {
                    if (sourceList.length < 2) {
                      return;
                    }
                    Routes.navigateTo(context, Routes.productList,
                        params: {'sourceId': sourceList[1].id});
                  },
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(12.w),
                    child: CachedNetworkImage(
                      imageUrl: sourceList.length > 1
                          ? CommonUtils.compressImageUrl(sourceList[1].imgPath, 342, 170)
                          : '',
                      fit: BoxFit.fill,
                      width: double.infinity,
                      height: double.infinity,
                      errorWidget: (context, url, error) {
                        return Image.asset(
                          'assets/images/bg_default_400.png',
                          width: double.infinity,
                          height: double.infinity,
                          fit: BoxFit.fill,
                        );
                      },
                    ),

                    // Image.network(
                    //   sourceList.length > 1 ? sourceList[1].imgPath : '',
                    //   fit: BoxFit.fill,
                    //   width: double.infinity,
                    //   height: double.infinity,
                    //   errorBuilder: (ctx, err, stacktrace) => Image.asset(
                    //     'assets/images/bg_default_400.png',
                    //     width: double.infinity,
                    //     height: double.infinity,
                    //     fit: BoxFit.fill,
                    //   ),
                    // ),
                  ),
                ),
              ),
            ],
          ),
        ),
        Container(
          height: 170.w,
          margin: EdgeInsets.only(top: 16.w),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              SizedBox(
                width: 342.w,
                height: double.infinity,
                child: InkWell(
                  onTap: () {
                    if (sourceList.length < 3) {
                      return;
                    }
                    Routes.navigateTo(context, Routes.productList,
                        params: {'sourceId': sourceList[2].id});
                  },
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(12.w),
                    child: CachedNetworkImage(
                      imageUrl: sourceList.length > 2
                          ? CommonUtils.compressImageUrl(sourceList[2].imgPath, 342, 170)
                          : '',
                      fit: BoxFit.fill,
                      width: double.infinity,
                      height: double.infinity,
                      errorWidget: (context, url, error) {
                        return Image.asset(
                          'assets/images/bg_default_400.png',
                          width: double.infinity,
                          height: double.infinity,
                          fit: BoxFit.fill,
                        );
                      },
                    ),

                    // Image.network(
                    //   sourceList.length > 2 ? sourceList[2].imgPath : '',
                    //   fit: BoxFit.fill,
                    //   width: double.infinity,
                    //   height: double.infinity,
                    //   errorBuilder: (ctx, err, stacktrace) => Image.asset(
                    //     'assets/images/bg_default_400.png',
                    //     width: double.infinity,
                    //     height: double.infinity,
                    //     fit: BoxFit.fill,
                    //   ),
                    // ),
                  ),
                ),
              ),
              SizedBox(
                width: 342.w,
                height: double.infinity,
                child: InkWell(
                  onTap: () {
                    if (sourceList.length < 4) {
                      return;
                    }
                    Routes.navigateTo(context, Routes.productList,
                        params: {'sourceId': sourceList[3].id});
                  },
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(12.w),
                    child: CachedNetworkImage(
                      imageUrl: sourceList.length > 3
                          ? CommonUtils.compressImageUrl(sourceList[3].imgPath, 342, 170)
                          : '',
                      fit: BoxFit.fill,
                      width: double.infinity,
                      height: double.infinity,
                      errorWidget: (context, url, error) {
                        return Image.asset(
                          'assets/images/bg_default_400.png',
                          width: double.infinity,
                          height: double.infinity,
                          fit: BoxFit.fill,
                        );
                      },
                    ),

                    // Image.network(
                    //   sourceList.length > 3 ? sourceList[3].imgPath : '',
                    //   fit: BoxFit.fill,
                    //   width: double.infinity,
                    //   height: double.infinity,
                    //   errorBuilder: (ctx, err, stacktrace) => Image.asset(
                    //     'assets/images/bg_default_400.png',
                    //     width: double.infinity,
                    //     height: double.infinity,
                    //     fit: BoxFit.fill,
                    //   ),
                    // ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    ),
  );
}

Widget getMallHomeModule5(
    String imgUrl1, String imgUrl2, String imgUrl3, String imgUrl4, String imgUrl5) {
  return Container(
    margin: EdgeInsets.only(top: 40.w, left: 25.w, right: 25.w),
    decoration: const BoxDecoration(color: Colors.transparent),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          margin: const EdgeInsets.symmetric(vertical: 0, horizontal: 0),
          child: Row(
            children: [
              Text('大牌精选', style: TextStyle(color: (Config.colorText1), fontSize: 30.sp)),
            ],
          ),
        ),
        Container(
          height: 370.w,
          margin: EdgeInsets.only(top: 20.w),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              SizedBox(
                width: 222.w,
                height: double.infinity,
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(12.w),
                  child: Image.network(
                    imgUrl1,
                    fit: BoxFit.fill,
                    width: double.infinity,
                    height: double.infinity,
                  ),
                ),
              ),
              SizedBox(
                width: 222.w,
                height: double.infinity,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    SizedBox(
                      height: 176.w,
                      width: double.infinity,
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(12.w),
                        child: Image.network(
                          imgUrl2,
                          fit: BoxFit.fill,
                          width: double.infinity,
                          height: double.infinity,
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 176.w,
                      width: double.infinity,
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(12.w),
                        child: Image.network(
                          imgUrl3,
                          fit: BoxFit.fill,
                          width: double.infinity,
                          height: double.infinity,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              SizedBox(
                width: 222.w,
                height: double.infinity,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    SizedBox(
                      height: 176.w,
                      width: double.infinity,
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(12.w),
                        child: Image.network(
                          imgUrl4,
                          fit: BoxFit.fill,
                          width: double.infinity,
                          height: double.infinity,
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 176.w,
                      width: double.infinity,
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(12.w),
                        child: Image.network(
                          imgUrl5,
                          fit: BoxFit.fill,
                          width: double.infinity,
                          height: double.infinity,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ],
    ),
  );
}

Widget getMallHomeModule6(String imgUrl1, String imgUrl2, String imgUrl3, String imgUrl4,
    String imgUrl5, String imgUrl6) {
  return Container(
    margin: EdgeInsets.only(top: 40.w, left: 25.w, right: 25.w),
    decoration: const BoxDecoration(color: Colors.transparent),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          margin: const EdgeInsets.symmetric(vertical: 0, horizontal: 0),
          child: Row(
            children: [
              Text('年中大促', style: TextStyle(color: (Config.colorText1), fontSize: 30.sp)),
            ],
          ),
        ),
        Container(
          height: 170.w,
          margin: EdgeInsets.only(top: 20.w),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              SizedBox(
                width: 342.w,
                height: double.infinity,
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(12.w),
                  child: Image.network(
                    imgUrl1,
                    fit: BoxFit.fill,
                    width: double.infinity,
                    height: double.infinity,
                  ),
                ),
              ),
              SizedBox(
                width: 342.w,
                height: double.infinity,
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(12.w),
                  child: Image.network(
                    imgUrl2,
                    fit: BoxFit.fill,
                    width: double.infinity,
                    height: double.infinity,
                  ),
                ),
              ),
            ],
          ),
        ),
        Container(
          height: 160.w,
          margin: EdgeInsets.only(top: 16.w),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              SizedBox(
                width: 342.w,
                height: double.infinity,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    SizedBox(
                      width: 162.w,
                      height: double.infinity,
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(12.w),
                        child: Image.network(
                          imgUrl3,
                          fit: BoxFit.fill,
                          width: double.infinity,
                          height: double.infinity,
                        ),
                      ),
                    ),
                    SizedBox(
                      width: 162.w,
                      height: double.infinity,
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(12.w),
                        child: Image.network(
                          imgUrl4,
                          fit: BoxFit.fill,
                          width: double.infinity,
                          height: double.infinity,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              SizedBox(
                width: 342.w,
                height: double.infinity,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    SizedBox(
                      width: 162.w,
                      height: double.infinity,
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(12.w),
                        child: Image.network(
                          imgUrl5,
                          fit: BoxFit.fill,
                          width: double.infinity,
                          height: double.infinity,
                        ),
                      ),
                    ),
                    SizedBox(
                      width: 162.w,
                      height: double.infinity,
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(12.w),
                        child: Image.network(
                          imgUrl6,
                          fit: BoxFit.fill,
                          width: double.infinity,
                          height: double.infinity,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ],
    ),
  );
}

//返回今日推荐item
getListItem(String movieId, String imgurl, String title) {
  return InkWell(
    onTap: () {
      // Routes.navigateTo(context, Routes.movieDetail,
      //     params: {'movieId': movieId});
    },
    child: Container(
      padding: EdgeInsets.fromLTRB(10.w, 0, 10.w, 0),
      width: 300.w,
      child: Column(
        children: [
          ClipRRect(
            borderRadius: BorderRadius.circular(5),
            child: Image.network(
              imgurl,
              fit: BoxFit.fill,
              width: double.infinity,
              height: 275.w,
            ),
          ),
          const Padding(padding: EdgeInsets.all(2)),
          Text(
            title,
            softWrap: false,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(color: (Config.colorText1), fontSize: 25.sp),
          ),
        ],
      ),
    ),
  );
}

Widget getMallHomeModuleToday() {
  return Container(
    margin: EdgeInsets.fromLTRB(0, 40.w, 0, 0),
    decoration: const BoxDecoration(color: Colors.transparent),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          margin: EdgeInsets.only(left: 30.w, right: 30.w, bottom: 25.w),
          child: Row(
            children: [
              // const Icon(Icons.local_fire_department, size: 20),
              // const SizedBox(width: 10, height: 10),
              Text('今日推荐', style: TextStyle(color: (Config.colorText1), fontSize: 30.sp)),
            ],
          ),
        ),
        SizedBox(
          width: double.infinity,
          height: 320.w,
          child: ListView.builder(
            itemCount: 5,
            padding: const EdgeInsets.symmetric(vertical: 0, horizontal: 5),
            shrinkWrap: true,
            scrollDirection: Axis.horizontal,
            physics: const BouncingScrollPhysics(),
            itemBuilder: (BuildContext context, int index) {
              return getListItem("WAHAHA",
                  "https://img.zcool.cn/community/01816558443778a801219c77f01608.jpg", "WAHAHA");
            },
          ),
        ),
      ],
    ),
  );
}
